﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Management.Automation;
using CrystalDecisions.Enterprise.Desktop;

namespace BO.Management.PowerShell
{
    [Cmdlet(VerbsCommon.Set, "HyperLink", DefaultParameterSetName = CONNECT_SECWINAD)]
    public class SetHyperLink:BaseBOECmdlet
    {
        [Parameter(Position = 3, ParameterSetName = CONNECT_SECENTERPRISE, Mandatory = true, ValueFromPipeline = true)]
        [Parameter(Position = 1, ParameterSetName = CONNECT_SECWINAD, Mandatory = true, ValueFromPipeline = true)]
        [ValidateNotNullOrEmpty]
        public Folder InputObject { get; set; }

        [Parameter(Position = 4, ParameterSetName = CONNECT_SECENTERPRISE, Mandatory = true)]
        [Parameter(Position = 2, ParameterSetName = CONNECT_SECWINAD, Mandatory = true)]
        [ValidateNotNullOrEmpty]
        public String Title { get; set; }

        [Parameter(Position = 5, ParameterSetName = CONNECT_SECENTERPRISE, Mandatory = true)]
        [Parameter(Position = 3, ParameterSetName = CONNECT_SECWINAD, Mandatory = true)]
        [ValidateNotNullOrEmpty]
        public String Url { get; set; }


        protected override void ProcessRecord()
        {
            base.ProcessRecord();


            using (HyperLinkProvider provider = new HyperLinkProvider(this.LogonProvider))
            {
                Hyperlink newLink = provider.GetNewObject();
                newLink.ParentID = this.InputObject.ID;
                newLink.Title = this.Title;
                newLink.Name = this.Url;
                provider.Commit(newLink);
            }

        }
    }
}
